//
//  XJ_CardListCell.m
//  XunJieProject
//
//  Created by 薛子 on 2018/6/11.
//  Copyright © 2018年 Soowin. All rights reserved.
//

#import "XJ_CardListCell.h"
#import "UIImage+image.h"
@implementation XJ_CardListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [_addHuanKuanBtn setImageEdgeInsets:UIEdgeInsetsMake(7,0, 7, 10)];
    [_addHuanKuanBtn setImage:[UIImage imageWithOriginalName:@"img_hk_bg"] forState:UIControlStateNormal];
    [_addHuanKuanBtn setTitle:@"添加还款计划" forState:UIControlStateNormal];
    
    // Initialization code
}

- (void)setCellData:(XJ_HomeCardListMode *)cardListModel{
    
    [_cardLogo sd_setImageWithURL:[NSURL URLWithString:cardListModel.cardLogo] placeholderImage:[UIImage imageNamed:@"img_no_image"]];
    NSString * cardNoStr = cardListModel.cardNo;
    NSString * lastFourStr;
    
    if (cardNoStr.length > 4) {
        
        lastFourStr = [cardListModel.cardNo substringWithRange:NSMakeRange(cardNoStr.length - 4, 4)];
    }
    cardNoStr = [NSString stringWithFormat:@"*** *** *** *** %@",lastFourStr];
    
    NSMutableAttributedString *cardNoText=[[NSMutableAttributedString alloc]initWithString:cardNoStr attributes:nil];
    
    [cardNoText addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(cardNoText.length - 4, 4)];
    _cardNoLabel.attributedText = cardNoText;
    
    _nameLabel.text = cardListModel.cardUserName;
    _bankNameLabel.text = cardListModel.bank;
    _zdrContentLabel.text = [NSString stringWithFormat:@"%@日",cardListModel.billDate];
    _hkrContentLabel.text = [NSString stringWithFormat:@"%@日",cardListModel.backMoneyDate];
    _yhContentLabel.text = [NSString stringWithFormat:@"￥%@",cardListModel.alreadyBackMoney];
    [_addHuanKuanBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _addHuanKuanBtn.layer.borderWidth = 1;
    _addHuanKuanBtn.layer.borderColor = [UIColor blackColor].CGColor;
    _addHuanKuanBtn.layer.cornerRadius = 15;
    
    if (cardListModel.backPlan == 0) {
        
        [_addHuanKuanBtn setTitle:@"添加还款计划" forState:UIControlStateNormal];
        
    }else{
        
        if (cardListModel.backPlan == 1 && cardListModel.planUseFlag == 0) {
            
            [_addHuanKuanBtn setTitle:@"查看未提交计划" forState:UIControlStateNormal];
            
        }else if (cardListModel.backPlan == 1 && cardListModel.planUseFlag == 1){
            
            [_addHuanKuanBtn setTitle:@"查看还款计划" forState:UIControlStateNormal];
        }
    }
}

- (NSString *)getNewBankNumWitOldBankNum:(NSString *)bankNum
{
    NSMutableString *mutableStr;
    if (bankNum.length) {
        mutableStr = [NSMutableString stringWithString:bankNum];
        for (int i = 0 ; i < mutableStr.length; i ++) {
            if (i<mutableStr.length - 4) {
                [mutableStr replaceCharactersInRange:NSMakeRange(i, 1) withString:@"*"];
            }
        }
        
        NSString *doneTitle = @"";
        int count = 0;
        for (int i = 0; i < mutableStr.length; i++) {
            
            count++;
            doneTitle = [doneTitle stringByAppendingString:[mutableStr substringWithRange:NSMakeRange(i, 1)]];
            
           
            if (count == 3) {
                doneTitle = [NSString stringWithFormat:@"%@ ", doneTitle];
                count = 0;
            }
            
//            if (i==3) {
//                doneTitle = [NSString stringWithFormat:@"%@ ", doneTitle];
//            }else if (i==7) {
//                doneTitle = [NSString stringWithFormat:@"%@ ", doneTitle];
//            }else if (i==11) {
//                doneTitle = [NSString stringWithFormat:@"%@ ", doneTitle];
//            }else if (i==15) {
//                doneTitle = [NSString stringWithFormat:@"%@ ", doneTitle];
//            }
        }
        NSLog(@"%@", doneTitle);
        return doneTitle;
    }
    return bankNum;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
